<?php

class Control_Model_Table_Scroller extends Zend_Db_Table_Abstract
{
    protected $_name = 'scroller';
    
    public function getUpperScroll()
    {
        $select = $this->select();
        $select->order('id DESC')
               ->where('upper=1')
               ->limit('5');
        $UpperScrollData = $this->_db->query($select)->fetchAll();
        return $UpperScrollData;
    }

        public function getLowerScroll()
    {
        $select = $this->select();
        $select->order('id DESC')
               ->where('upper=0')
               ->limit('5');
        $UpperScrollData = $this->_db->query($select)->fetchAll();
        return $UpperScrollData;
    }


        public function getDataID($id)
    {
        $id = (int)$id;
        $row = $this->fetchRow('id ='.$id);
        if (!$row) {
 //           throw new Exception("Count not find row $id");
        }else{return $row->toArray();}
    }

    public function addServices($name, $text)
    {
         $data = array(
            'name' => $name,
            'text' => $text,
            'upper' => '0');
        $this->insert($data);
    }

    public function getAll()
    {
        $select = $this->select();
        $select->order('id DESC');
        $Data = $this->_db->query($select)->fetchAll();
        return $Data;
    }

        public function getAllServices()
    {
        $select = $this->select();
        $select->where('upper=0')
                ->order('id DESC');
        $Data = $this->_db->query($select)->fetchAll();
        return $Data;
    }

    public function updateServices($id, $name, $text)
    {
        $data = array(
            'name' => $name,
            'text' => $text,
            'upper' => '0');
        $this->update($data,'id= '.(int)$id);
    }

        public function deleteData($id)
    {
        $this->delete('id ='.(int)$id);
    }

            public function getScroller()
    {
        $select = $this->select();
        $select->where('upper=1')
                ->order('id DESC');
        $Data = $this->_db->query($select)->fetchAll();
        return $Data;
    }

        public function addScroll($name, $text, $image, $link)
    {
         $data = array(
            'name' => $name,
            'text' => $text,
            'image' => $image,
            'link' => $link,
            'upper' => '1');
        $this->insert($data);
    }

        public function updateScroll($id, $name, $text, $image, $link)
    {
        $data = array(
            'name' => $name,
            'text' => $text,
            'link' => $link,
        );
        if ($logo!=""){
        $logo = array('image' => $image,);
        $data=$logo+$data;
        }
        $this->update($data,'id= '.(int)$id);
    }

}

